import 'package:flutter/material.dart';

class AnimatedDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _AnimatedDemoState();
  }
}

class _AnimatedDemoState extends State<AnimatedDemo> {
  double _padding = 10;
  Alignment _align = Alignment.topRight;
  double _height = 100;
  double _left = 0;
  Color _color = Colors.red;
  TextStyle _style = TextStyle(color: Colors.black);

  @override
  Widget build(BuildContext context) {
    final duration = Duration(seconds: 1);
    return Scaffold(
      appBar: AppBar(
        title: Text('动画组件的例子'),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            RaisedButton(
              onPressed: () {
                setState(() {
                  _padding = 20;
                });
              },
              child: AnimatedPadding(
                duration: duration,
                padding: EdgeInsets.all(_padding),
                child: Text("AnimatedPadding"),
              ),
            ),

            SizedBox(
              height: 50,
              child: Stack(
                children: <Widget>[
                  AnimatedPositioned(
                    duration: duration,
                    left: _left,
                    child: RaisedButton(
                      onPressed: () {
                        setState(() {
                          _left = 100;
                        });
                      },
                      child: Text("AnimatedPositioned"),
                    ),
                  )
                ],
              ),
            ),

            Container(
              height: 100,
              color: Colors.grey,
              child: AnimatedAlign(
                duration: duration,
                alignment: _align,
                child: RaisedButton(
                  onPressed: () {
                    setState(() {
                      _align = Alignment.center;
                    });
                  },
                  child: Text("AnimatedAlign"),
                ),
              ),
            ),

            AnimatedContainer(
              duration: duration,
              height: _height,
              color: _color,
              child: FlatButton(
                onPressed: () {
                  setState(() {
                    _height = 150;
                    _color = Colors.blue;
                  });
                },
                child: Text(
                  "AnimatedContainer",
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),

            AnimatedDefaultTextStyle(
              child: GestureDetector(
                child: Text("hello world"),
                onTap: () {
                  setState(() {
                    _style = TextStyle(
                      color: Colors.blue,
                      decorationStyle: TextDecorationStyle.solid,
                      decorationColor: Colors.blue,
                    );
                  });
                },
              ),
              style: _style,
              duration: duration,
            ),

            RaisedButton(onPressed: (){
              setState(() {
                _padding = 10;
                _align = Alignment.topRight;
                _height = 100;
                _left = 0;
                _color = Colors.red;
                _style = TextStyle(color: Colors.black);
              });
            }, child: Text('参数还原'),),

            RaisedButton(onPressed: (){
              setState(() {
                _padding = 20;
                _align = Alignment.center;
                _height = 150;
                _left = 100;
                _color = Colors.blue;
                _style = TextStyle(color: Colors.blue,
                  decorationStyle: TextDecorationStyle.solid,
                  decorationColor: Colors.blue,
                );
              });
            }, child: Text('一键设置'),),
          ].map((e){
            return Padding(padding: EdgeInsets.all(16), child: e);
          }).toList(),
        ),
      ),
    );
  }
}